package com.akupilih.app;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.support.v4.view.ViewPager;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.ImageView;
import android.widget.ScrollView;

import com.akupilih.app.adapter.PasanganAdapter;
import com.akupilih.app.helper.PagerSlidingTabStrip;
import com.akupilih.app.model.Utils;

public class PasanganActivity extends BaseActivity implements OnClickListener {
	private ViewPager mViewPager;
	private PagerSlidingTabStrip tabs;
	String kode = "";
	private ImageView capres, cawapres;
	PasanganAdapter titleAdapter;

	public PasanganActivity() {
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pasangan);
		getActionBar().setDisplayHomeAsUpEnabled(true);
		mViewPager = (ViewPager) findViewById(R.id.viewpager);
		Bundle b = getIntent().getExtras();
		kode = b.getString("kode");
		Utils.TRACE("PasanganActivity", "onCreate : " + kode);

		capres = (ImageView) this.findViewById(R.id.activity_pasangan_capres);
		cawapres = (ImageView) this
				.findViewById(R.id.activity_pasangan_cawapres);

		if (kode.equals("ps_hr")) {
			Utils.TRACE("PasanganActivity", "onCreate : set prabowo");
			setTitle("Prabowo - Hatta");
			capres.setBackgroundResource(R.drawable.bg_prabowo_state);
			cawapres.setBackgroundResource(R.drawable.bg_hatta_state);
			titleAdapter = new PasanganAdapter(getSupportFragmentManager(),
					"ps", "hr");
		} else {
			setTitle("Jokowi - JK");
			Utils.TRACE("PasanganActivity", "onCreate : set bg jokowi");
			capres.setBackgroundResource(R.drawable.bg_jokowi_state);
			cawapres.setBackgroundResource(R.drawable.bg_jk_state);
			titleAdapter = new PasanganAdapter(getSupportFragmentManager(),
					"jk", "jw");
		}

		/** Defining a listener for pageChange */

		tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
		mViewPager.setAdapter(titleAdapter);
		mViewPager.setCurrentItem(0);
		tabs.setViewPager(mViewPager);
		tabs.setIndicatorColor(Color.parseColor("#CC0000"));
		tabs.setIndicatorHeight(3);

		capres.setOnClickListener(this);
		cawapres.setOnClickListener(this);

	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		// Respond to the action bar's Up/Home button
		case android.R.id.home:
			NavUtils.navigateUpFromSameTask(this);
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		Bundle b = new Bundle();
		if (v == capres) {
			b.putString("kode", kode); // Your id
			b.putInt("key", 1);
		} else {
			b.putString("kode", kode); // Your id
			b.putInt("key", 2);
		}
		startActivity(new Intent(this, IndividuActivity.class).putExtras(b));

	}
}
